
<template>
    <div class="list-page">
        <!-- 顶部按钮 -->
        <div class="but1">
        <router-link to="/home">
         	<el-button type="warning" size="small"  style='margin-right: 5px;'  icon="el-icon-menu">首页</el-button>
        </router-link>
        <!-- <el-button type="success" size="small" @click='componentsShow("add")' icon="el-icon-edit">添加</el-button> -->
        <!--<el-button type="danger" size="small" :disabled="multipleDeleteDisabled" icon="el-icon-delete" @click="componentsShow('multipleDelete','')">批量删除</el-button>-->
        </div>
        <!-- 模糊搜索条件 -->
        <div class="search">
        	<div class="search-item">
        		<!--<span>今天</span>-->
                <el-date-picker  v-model="vbtime"  type="date" class="code-search" placeholder="选择开始日期" @keyup.enter.native="search">  </el-date-picker>
                <span>--</span>
               
                <el-date-picker  v-model="vetime"  type="date" class="code-search" placeholder="选择结束日期" @keyup.enter.native="search">  </el-date-picker>
       		 <!--<span>未来一周</span>--> 
        	</div>
        	<div class="search-item">
				<el-select v-model="vlsid" placeholder="请选择老师" class="code-search">
					<el-option :label="v.zwm" :value="v.id" v-for="v in comboxlist"></el-option>
				</el-select>
       		 </div>
       		<div class="search-item">
				<el-select v-model="vjsid" placeholder="请选择教室" class="code-search" >
			    <el-option :label="v.jsmc" :value="v.id " v-for="v in jsboxlist"></el-option>
				</el-select>
		    </div>
                <el-button type="primary" size="small" style='border-radius:13px ;' :loading="searchLoading" @click="search" icon="el-icon-search"></el-button>
        </div>

        <!-- 数据表格展示区域 -->
        <el-table
            :data="dataList"
             stripe
             border
            align="left"
            style="width:100%"
            class="admin-table"
            @select="checkSelect"
            @select-all="checkall">
            <div slot='empty'>
                <img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
                <span style="vertical-align: middle;">暂时还没有内容哦!</span>
            </div>
            <!--<el-table-column type="selection" width="55"></el-table-column>-->


            <el-table-column
                :prop="v.prop"
                :label="v.label"
                v-for="(v,index) in portTitleList"
                align="center"
                show-overflow-tooltip
                v-if="v.hide != 0"
                :formatter="v.formatter"
                :align="v.align || 'center'"
                :fixed="v.fixed"
                :class-name="v.columnStyle"
                :width="v.width"
                :min-width="v.minWidth"
                :header-align="v.headerAlign || 'center'"
                >
                <template scope="scope">
                    <div slot="reference" :style="tableCellControl(scope)">
                        {{ scope.row[scope.column.property] }}
                    </div>
                 </template>
            </el-table-column>

            <el-table-column
                label="操作"
                width="150px"
                align="center"
                :fixed="'right'">
                <template scope="scope">
                    <el-button size="small" type="primary" @click="componentsShow(v.type,scope)" v-for="v in portBntList">{{v.name}}</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页查询区域 -->
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="pageindex"
            :page-sizes="pagesizes"
            :page-size="pagesize"
            :layout="layout"
            :total="total"
            class="class-page">
        </el-pagination>


        <!-- 各个组件显示区域 -->

        <!-- 动画加载 -->
        <LoadingComponent v-show="isLoading"></LoadingComponent>

        <!-- 添加组件 -->
        <AddComponent v-if="componentList.add.toggle" @close="componentsHide"></AddComponent>

        <!--学生组件-->
        <StudentTableComponent v-if="componentList.student.toggle"  @close="componentsHide"  :params="componentList.student.params"></StudentTableComponent>

        <!-- 排课组件 -->
        <SchedulingComponent v-if="componentList.pk.toggle"  @close="componentsHide"  :params="componentList.pk.params"></SchedulingComponent>

        <!-- 课表组件 -->
        <ClassTableComponent style="height:800px; position:absolute; width:100%;" v-if="componentList.course.toggle"  @close="componentsHide"  :params="componentList.course.params"></ClassTableComponent>


        <!-- 单独删除组件 -->
        <DeleteComponent v-if="componentList.singleDelete.toggle"  @close="componentsHide"  :data="componentList.singleDelete.data"></DeleteComponent>

        <!-- 批量删除组件 -->
        <DeleteComponent v-if="componentList.multipleDelete.toggle"  @close="componentsHide"  :data="componentList.multipleDelete.data"></DeleteComponent>

        <!-- 子路由显示区域 -->
        <router-view class="port-view"></router-view>
    </div>
</template>

<script>
    import { mapState } from 'vuex'
    import qs from 'qs'
    import LoadingComponent from 'components/loading'
    import SchedulingComponent from './scheduling'
    import ClassTableComponent from './class-table'
    import StudentTableComponent from './student-table'
    import AddComponent from './add'
    // import EditComponent from './edit'
    // import InfoComponent from './info'
    import DeleteComponent from './del'

    export default {
        components: {
            LoadingComponent,
            DeleteComponent,
            AddComponent,
            // EditComponent,
            // InfoComponent
            SchedulingComponent,
            ClassTableComponent,
            StudentTableComponent
        },
        data () {
            return {
            	vjsid:'',
            	vlsid:'',
            	vbtime:'',
            	vetime:'',
               comboxlist:[],
               jsboxlist:[],
                /*组件区域*/
                componentList: {
                    singleDelete: {
                        type: 'singleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'single',
                            title: '此操作将删除该班级, 是否继续?'
                        }
                    },
                    multipleDelete: {
                        type: 'multipleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'multiple',
                            title: '此操作将删除您选中的班级, 是否继续?'
                        }
                    },
                    add: {
                        type: 'add',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    edit: {
                        type: 'edit',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    info: {
                        type: 'info',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    pk: {
                        type: 'pk',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    course: {
                        type: 'course',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    student:{
                    	type:'student',
                    	toggle: false,
                    	params:'',
                    	data: {}
                    }
                },

                multipleDelNum:'', //获取批量选择的数据
                dataList: [],  //表格数据

                /*
                    prop :  接口参数名
                    label : 接口中文名
                    hide : 是否隐藏这一列
                    align : 这一列对齐顺序 ： left,right,center
                    headerAlign : 这一列表头对齐方式 ： left,right,center
                */
                portTitleList: [

                    {
                        prop:'id',
                        label:'id',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'sj',
                        label:'上课日期',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'mc',
                        label:'班级名称',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'lsmc',
                        label:'老师名称',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'jsmc',
                        label:'教室名称',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    
                    {
                        prop:'day',
                        label:'Day',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'zt',
                        label:'状态',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    
                    {
                        prop:'zks',
                        label:'总课时',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'ysks',
                        label:'已上课时',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'dklsgh',
                        label:'代课老师工号',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'dklsmc',
                        label:'代课老师名称',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'isskmc',
                        label:'是否上课',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'isdkjsmc',
                        label:'是否结束代课',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'skday',
                        label:'实际上课的day 由考勤时写入',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    }

                ],
                portBntList: [//接口按钮列表
                    // {
                    //     name:'排课',
                    //     type:'pk'
                    // },
                    {
                        name:'课表',
                        type:'course'
                    },
                    // {
                    //     name:'学生列表',
                    //     type:'student'
                    // },
//                  {
//                      name:'删除',
//                      type:'singleDelete'
//                  }
                ],

                /*动画加载*/
                isLoading: true,//动画加载
                searchLoading: false,//搜索按钮触发按钮动画


                /*分页属性设置*/
                layout: 'total, sizes, prev, pager, next, jumper',//组件布局
                pageindex: 1,//当前分页页码
                pagesizes: [12, 24, 36, 72],//显示个数的选择器选项
                pagesize: 12,//每页显示条目数
                total: 0,//总条数


                dropDownData:'', //

            }
        },
        created () {

	         this.vbtime = this.addDate(new Date() ,-6 ); 
	         this.vetime =  this.addDate(new Date() ,0 ); 
         		
            //加载页面时调用
            this.$store.dispatch('changeTitle','排课管理');//修改title
            this.$store.dispatch('changeRouterIndex','/educa/course');//修改路由

            this.search();//分页获取默认数据
            this.getcomboxlist();
            this.getjslist();
            this.isLoading = true;//动画开始

            // this.$.getHolidays()
            if(this.$route.query.iid) {
               			this.componentsShow("course");
      			}

        },
        mounted () {
            this.isLoading = false;//动画结束
        },
        methods: {
        			getFormatDate(date) {
				var seperator1 = "-";
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				var strDate = date.getDate();
				if(month >= 1 && month <= 9) {
					month = "0" + month;
				}
				if(strDate >= 0 && strDate <= 9) {
					strDate = "0" + strDate;
				}
				var currentdate = year + seperator1 + month + seperator1 + strDate;
				return currentdate;
			},
        		addDate(date, days ) {
				var d = new Date(date);
				d.setDate(d.getDate() + days);
				return this.getFormatDate(d);
			},
			
//          tableRowClassName (row, index) {//隔行变色颜色设置
//             if ( index%4 == 0) {
//                  return "table-cell-green";
//              }else if( index%4 == 1 ){
//                  return "table-cell-yellow";
//              }else if( index%4 == 2 ){
//                  return "table-cell-red";
//              }else{
//                  return "table-cell-blue"
//              }
//          },
            tableCellControl (scope) {//表格单元格控制CSS样式
                /*if (scope.row.id == 112 && scope.column.property == "iname") {
                    return {
                        color:"red",
                    }
                }else{
                    return {
                        color:"green",
                    }
                }*/
            },
            getjslist(){
				var logininfo = JSON.parse(localStorage.logininfo);
              this.searchLoading = true;
             var params2 = qs.stringify({
                      yhid:logininfo.id,
                      xxid:logininfo.xxid
               })
             //执行
                 this.axios.post(this.$store.state.api + 'xxjs/getjsxlk',  params2 )
                 .then(res => {
							let data = res.data.data.list;
							this.jsboxlist = data;
                 }).catch(res => {
				})
			},
            getcomboxlist() {
			var logininfo = JSON.parse(localStorage.logininfo);
              this.searchLoading = true;
              var params2 = qs.stringify({
                     yhid: logininfo.id,
						xxid: logininfo.xxid
               })
             //执行
                 this.axios.post(this.$store.state.api + 'ls/getlsxlk',  params2 )
                 .then(res => {
                 console.log(res)
					let data = res.data.data;
					let list = data.list;
					this.comboxlist = list;
                 }).catch(res => {
					 console.log(res)
                  this.searchLoading = false;
				})
			},
            search () {//查询搜索触发事件
             var time1 = this.$.getLocalTimeNo0(Date.parse(this.vbtime));
	         var time2 = this.$.getLocalTimeNo0(Date.parse(this.vetime));
             var logininfo = JSON.parse(localStorage.logininfo);
             this.searchLoading = true;
             var params2 = qs.stringify({
             	        btime: time1,
                        etime: time2,
                        jsid: this.vjsid,
                        keyword:this.vlsid , 
                        pageindex: this.pageindex,
                        pagesize: this.pagesize,
                        yhid: logininfo.id,
					    xxid: logininfo.xxid
               })
             //执行
                 this.axios.post(this.$store.state.api + 'pk/list',  params2 )
                 .then(res => {
                 console.log('222',res)
                    let data = res.data.data;
                    let list = data.list;
                    this.total = data.totalPage;
                    this.dataList = list;
                    this.searchLoading = false;
                 }).catch(res => {
					 console.log(res)
                  this.searchLoading = false;
				})
            },
            handleSizeChange (val) {//每页显示条数触发事件
                this.pagesize = val;
                this.pageindex = 1;
                this.search();
            },
            handleCurrentChange (val) {//分页触发事件
                this.search();
            },
            checkSelect (selection, row) {//点击单选select触发事件
                console.log(selection)
                console.log(111)
                let strID = [];
                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                this.multipleDelNum = strID.join(",");
            },
            checkall (selection) {//点击全选select触发事件
                // console.log(selection)
                let strID = [];

                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                // console.log(strID.join(","))
                this.multipleDelNum = strID.join(",");
                // console.log(strID)
            },







            /* 组件的弹框  */
            componentsShow (type,data) { //显示组件
                console.log(type,data)
                for ( let i in this.componentList ) {
                    if (type == this.componentList[i].type) {

                        this.componentList[i].toggle = true;
                        this.componentList[i].params = data;

                        if (this.componentList[i].data.type == 'single') {
                            this.componentList[i].data.index = data.row.id

                        }else if(this.componentList[i].data.type == 'multiple'){
                            this.componentList[i].data.index = this.multipleDelNum;

                        }else{
                            return;
                        }
                        return;
                    }
                }
            },
            componentsHide (setting) { //关闭组件
              this.search();
                for ( let i in this.componentList ) {
                    if (setting.type == this.componentList[i].type) {
                        this.componentList[i].toggle = false;

                        if (!setting.cancel) {
                           this.search();
                        }
                        return;
                    }
                }
            }

        },
        computed: {
            ...mapState([
                'api'//域名
            ]),
            multipleDeleteDisabled () {
                console.log(this.multipleDelNum)
                if (this.multipleDelNum) {
                    return false;
                }else{
                    return true
                }
            }
        },
        // watch: {
        //     dataList () {
        //         let arr = [];
        //         // console.log(this.dataList.length)
        //         for ( let i = 0; i < this.dataList.length; i ++) {
        //             this.dataList[i].number = this.pagesize * (this.pageindex - 1) + i + 1;
        //         }
        //     }
        // }
    }
</script>

<style lang="less" scoped>
    .list-page {
        font-size:12px;
        position: relative;
        width: 100%;
        height: 100%;

        .btn {
            height: 30px;
            padding:0 10px;
            margin-left: 0 ;
        }
        .code-search {
            height: 30px;
            margin:10px 0 10px 0;
             min-width: 100px;
            max-width: 135px;
        }
        .class-page {
            text-align: left;
            margin-top:10px;
        }

        .search-item {
            display: inline-block;
            margin-right:5px;
        }
        .but1{
			width: 20%;
			float: left;
			margin-top: 8px
		}
		.search{
			width: 80%;
			float: right;
			text-align: right;
		}
		.el-button+.el-button {
            margin-left: 5px;
        }


    }
</style>
